// Attach a handler to the load event, to show the grid A,B values when the page
// is finished loading.
Sys.Application.add_load(loadGrid);

function loadGrid() {
    DrawMatrix(0); //Show Grid
}

//register namespace
Type.registerNamespace('ScottCate');

ScottCate.MathOperator = function() {}
ScottCate.MathOperator.prototype = {
    None: 0,
    Add: 1,
    Subtract: 2,
    Multiply: 3,
    Divide: 4
}

ScottCate.MathOperator.registerEnum('ScottCate.MathOperator', false);

//create base signature.
ScottCate.Math = function(a,b) {
    this._a = a; //value of a or 0
    this._b = b; //value of b or 0
}

ScottCate.Math.prototype = {
    get_a : function() { return this._a; },
    get_b : function() { return this._b; },
    toString : function () { return this.get_a() + ',' + this.get_b() },
    dispose : function() {}
}

//Add
ScottCate.AddMath = function(a,b) {
    ScottCate.AddMath.initializeBase(this, [a,b]);
}
ScottCate.AddMath.prototype.toString = function() {
    return this.get_a() + this.get_b();
}

//Subtract
ScottCate.SubtractMath = function(a,b) {
    ScottCate.SubtractMath.initializeBase(this, [a,b]);
}
ScottCate.SubtractMath.prototype.toString = function() {
    return this.get_a() - this.get_b();
}

//Multiply
ScottCate.MultiplyMath = function(a,b) {
    ScottCate.MultiplyMath.initializeBase(this, [a,b]);
}
ScottCate.MultiplyMath.prototype.toString = function() {
    return this.get_a() * this.get_b();
}

//Divide
ScottCate.DivideMath = function(a,b) {
    ScottCate.DivideMath.initializeBase(this, [a,b]);
}
ScottCate.DivideMath.prototype.toString = function() {
    if(this.get_b() != 0)
        return this.get_a() / this.get_b();
    else
        return "div0 err";
}

//register classes
ScottCate.Math.registerClass('ScottCate.Math', null, Sys.IDisposable);
ScottCate.AddMath.registerClass('ScottCate.AddMath', ScottCate.Math);
ScottCate.SubtractMath.registerClass('ScottCate.SubtractMath', ScottCate.Math);
ScottCate.MultiplyMath.registerClass('ScottCate.MultiplyMath', ScottCate.Math);
ScottCate.DivideMath.registerClass('ScottCate.DivideMath', ScottCate.Math);


function DrawMatrix(selectedOperator) {
    //convert from int to eNum
    var selectedValue = parseInt(selectedOperator);
    
    switch(selectedValue) {
        case ScottCate.MathOperator.None : 
            BuildMatrix(ScottCate.Math);
            break;
        case ScottCate.MathOperator.Add :
            BuildMatrix(ScottCate.AddMath);
            break;
        case ScottCate.MathOperator.Subtract :
            BuildMatrix(ScottCate.SubtractMath);
            break;
        case ScottCate.MathOperator.Multiply :
            BuildMatrix(ScottCate.MultiplyMath);
            break;
        case ScottCate.MathOperator.Divide :
            BuildMatrix(ScottCate.DivideMath);
            break;
    }
}

function BuildMatrix(operationDelegate) {
    var matrix = $get('Matrix');
    var sb = new Sys.StringBuilder('<table border=0>');
    for(a=0;a<=10;a++) {
        sb.append('<tr>');
        for(b=0;b<=10;b++) {
            sb.append('<td style="border-color:Black;border-width:1px;border-style:solid;">');
            var operation = new operationDelegate(a,b);
            sb.append( operation.toString() );
            sb.append('</td>');
        }
        sb.append('</tr>');
    }
    sb.append('</table>');
    matrix.innerHTML = sb.toString();
}

 
 
 
 
 
 
 
 
 